# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "sonnet"
pkgver=5.109.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="Spell checking framework for Qt (mingw-w64)"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-hunspell"
             "${MINGW_PACKAGE_PREFIX}-aspell"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=()
if [ "${_variant}" = "-static" ]; then
  _kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
else
  makedepends+=("${MINGW_PACKAGE_PREFIX}-qt5-tools")
  depends+=("${MINGW_PACKAGE_PREFIX}-qt5-base"
            "${MINGW_PACKAGE_PREFIX}-qt5-declarative")
fi
optdepends=("${MINGW_PACKAGE_PREFIX}-hunspell: spell checking via hunspell"
            "${MINGW_PACKAGE_PREFIX}-aspell: spell checking via aspell")
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.tar.xz"{,.sig}
        001-drop-pre-win7-support.patch)
sha256sums=('593ba654a8b5f61af95fec3fd0b269a8f5e89dbed54d62aafb41a0ce0146eeba'
            'SKIP'
            '9e546a6881b470f3a1030b45604058525374d0e57839f12dfd25c78397012f61')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  mkdir -p build-${MSYSTEM}${_variant}

  cd "${_basename}-${pkgver}"
  patch -p1 -i ${srcdir}/001-drop-pre-win7-support.patch
}

build() {
  local -a extra_config
  cd build-${MSYSTEM}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_QCH=OFF \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    "${extra_config[@]}" \
    ../${_basename}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./
}
